﻿using DbToDocument.Core;
using DbToDocument.Core.LiteDB;
using DbToDocument.WebApp.Models;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;

namespace DbToDocument.WebApp.Controllers
{
    /// <summary>
    /// 首页
    /// </summary>
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;
        private readonly ILiteDBService _liteDBService;

        public HomeController(ILogger<HomeController> logger, ILiteDBService liteDBService)
        {
            _logger = logger;
            _liteDBService = liteDBService;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IActionResult Privacy()
        {
            return View();
        }

        /// <summary>
        /// 加载系统菜单
        /// </summary>
        /// <returns></returns>
        public JsonResult Menu()
        {
            var resultModel = new ResultModel<Menu[]>();
            resultModel.data = _liteDBService.menus().ToArray();
            return Json(resultModel);
        }




        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}